luci-mod-status,-network: remove checkUfpInstalled
authorDavid Härdeman <[email protected]>
Wed, 15 Oct 2025 13:07:32 +0000 (15:07 +0200)
committerPaul Donald <[email protected]>
Wed, 15 Oct 2025 23:24:42 +0000 (01:24 +0200)
Right now, the checkUfpInstalled RPC call is performed first, and only after
that can the other Promises be called. Simplify this by adding a single check
for /usr/sbin/ufpd in the rpcd ucode, and replace calls to checkUfpInstalled()
with simple L.hasSystemFeature('ufpd') check (which is only done once, and
cached).

This also allows the 'stat' permission to be removed from a couple of acls.

Signed-off-by: David Härdeman <[email protected]>
modules/luci-base/root/usr/share/rpcd/ucode/luci
modules/luci-mod-network/htdocs/luci-static/resources/view/network/dhcp.js
modules/luci-mod-network/root/usr/share/rpcd/acl.d/luci-mod-network.json
modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/40_dhcp.js
modules/luci-mod-status/htdocs/luci-static/resources/view/status/routes.js
modules/luci-mod-status/htdocs/luci-static/resources/view/status/routesj.js
modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status-index.json
modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status.json

index 1e20634d4cd765530965865f26cb8bf20f729f77..458c6573c2845fb3ad6b754adc50a89f31149452 100644 (file)
@@ -237,6 +237,7 @@ const methods = {
                                relayd:     access('/usr/sbin/relayd') == true,
                                apk:        access('/usr/bin/apk') == true,
                                wifi:       access('/sbin/wifi') == true,
+                               ufpd:       access('/usr/sbin/ufpd') == true,
                                vrf:        access('/sys/module/vrf/refcnt') == true, // vrf.ko is loaded
                                netifd_vrf: false,
                        };
index 95240f6a5ee551c2499579440dae135b0c344c1e..074dcfe95d097b2f165e926b0910aded2ccf0af9 100644 (file)
@@ -11,7 +11,7 @@
 'require tools.dnsrecordhandlers as drh';
 
 var callHostHints, callDUIDHints, callDHCPLeases, CBILeaseStatus, CBILease6Status;
-var checkUfpInstalled, callUfpList;
+var callUfpList;
 
 callHostHints = rpc.declare({
        object: 'luci-rpc',
@@ -31,12 +31,6 @@ callDHCPLeases = rpc.declare({
        expect: { '': {} }
 });
 
-checkUfpInstalled = rpc.declare({
-       object: 'file',
-       method: 'stat',
-       params: [ 'path' ]
-});
-
 callUfpList = rpc.declare({
        object: 'fingerprint',
        method: 'fingerprint',
@@ -289,19 +283,13 @@ function validateMACAddr(pools, sid, s) {
 return view.extend({
        load: function() {
                return Promise.all([
-                       checkUfpInstalled('/usr/sbin/ufpd')
-               ]).then(data => {
-                       var promises = [
-                               callHostHints(),
-                               callDUIDHints(),
-                               getDHCPPools(),
-                               network.getNetworks(),
-                               data[0].type === 'file' ? callUfpList() : null,
-                               uci.load('firewall')
-                       ]
-
-                       return Promise.all(promises);
-               });
+                       callHostHints(),
+                       callDUIDHints(),
+                       getDHCPPools(),
+                       network.getNetworks(),
+                       L.hasSystemFeature('ufpd') ? callUfpList() : null,
+                       uci.load('firewall')
+               ]);
        },
 
        render: function([hosts, duids, pools, networks, macdata]) {
index 42181f6ee22e80fbc12f9a3124583853a46c4c48..a297e03d79792f86eb06a37b1529219eb35673fc 100644 (file)
@@ -39,8 +39,7 @@
                "read": {
                        "ubus": {
                                "luci-rpc": [ "getDHCPLeases", "getDUIDHints", "getHostHints" ],
-                               "fingerprint": [ "fingerprint" ],
-                               "file": [ "stat" ]
+                               "fingerprint": [ "fingerprint" ]
                        },
                        "uci": [ "dhcp" ]
                },
index 27e903f2cdfafddbd68f42ef1701bb15d5c5b048..99dc67af52e4cc119c0d702792b3119236490c55 100644 (file)
@@ -16,12 +16,6 @@ var callUfpList = rpc.declare({
        method: 'fingerprint',
 });
 
-var checkUfpInstalled = rpc.declare({
-       object: 'file',
-       method: 'stat',
-       params: [ 'path' ]
-});
-
 return baseclass.extend({
        title: '',
 
@@ -30,17 +24,11 @@ return baseclass.extend({
 
        load: function() {
                return Promise.all([
-                       checkUfpInstalled('/usr/sbin/ufpd')
-               ]).then(data => {
-                       var promises = [
-                               callLuciDHCPLeases(),
-                               network.getHostHints(),
-                               data[0].type === 'file' ? callUfpList() : null,
-                               L.resolveDefault(uci.load('dhcp'))
-                       ];
-
-                       return Promise.all(promises);
-               });
+                       callLuciDHCPLeases(),
+                       network.getHostHints(),
+                       L.hasSystemFeature('ufpd') ? callUfpList() : null,
+                       L.resolveDefault(uci.load('dhcp'))
+               ]);
        },
 
        handleCreateStaticLease: function(lease, ev) {
index e48c1d65343e3ddb14c08ae65628a844e5d1a5bc..79ee5acef69924809596aeb1c9ab09a4cf0a250a 100644 (file)
@@ -11,12 +11,6 @@ const callNetworkInterfaceDump = rpc.declare({
        expect: { interface: [] }
 });
 
-const checkUfpInstalled = rpc.declare({
-       object: 'file',
-       method: 'stat',
-       params: [ 'path' ]
-});
-
 const callUfpList = rpc.declare({
        object: 'fingerprint',
        method: 'fingerprint',
@@ -44,19 +38,15 @@ function applyMask(addr, mask, v6) {
 return view.extend({
        load() {
                return Promise.all([
-                       checkUfpInstalled('/usr/sbin/ufpd')
-               ]).then(([ufpcheck]) => {
-                       return Promise.all([
-                               callNetworkInterfaceDump(),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-4', 'neigh', 'show' ]), {}),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-4', 'route', 'show', 'table', 'all' ]), {}),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-4', 'rule', 'show' ]), {}),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-6', 'neigh', 'show' ]), {}),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-6', 'route', 'show', 'table', 'all' ]), {}),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-6', 'rule', 'show' ]), {}),
-                               ufpcheck?.type === 'file' ? callUfpList() : null
-                       ]);
-               });
+                       callNetworkInterfaceDump(),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-4', 'neigh', 'show' ]), {}),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-4', 'route', 'show', 'table', 'all' ]), {}),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-4', 'rule', 'show' ]), {}),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-6', 'neigh', 'show' ]), {}),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-6', 'route', 'show', 'table', 'all' ]), {}),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-6', 'rule', 'show' ]), {}),
+                       L.hasSystemFeature('ufpd') ? callUfpList() : null
+               ]);
        },
 
        getNetworkByDevice(networks, dev, addr, mask, v6) {
index 001dd7acf39aa2cb4e42562fb7c2907cc1c18b6b..37409f721d83e8f4abb1a8cccb869ffe38663bd9 100644 (file)
@@ -12,12 +12,6 @@ const callNetworkInterfaceDump = rpc.declare({
        expect: { interface: [] }
 });
 
-const checkUfpInstalled = rpc.declare({
-       object: 'file',
-       method: 'stat',
-       params: [ 'path' ]
-});
-
 const callUfpList = rpc.declare({
        object: 'fingerprint',
        method: 'fingerprint',
@@ -45,19 +39,15 @@ function applyMask(addr, mask, v6) {
 return view.extend({
        load() {
                return Promise.all([
-                       checkUfpInstalled('/usr/sbin/ufpd')
-               ]).then(([ufpcheck]) => {
-                       return Promise.all([
-                               callNetworkInterfaceDump(),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-4', '-j', 'neigh', 'show' ]), {}),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-4', '-j', 'route', 'show', 'table', 'all' ]), {}),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-4', '-j', 'rule', 'show' ]), {}),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-6', '-j', 'neigh', 'show' ]), {}),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-6', '-j', 'route', 'show', 'table', 'all' ]), {}),
-                               L.resolveDefault(fs.exec('/sbin/ip', [ '-6', '-j', 'rule', 'show' ]), {}),
-                               ufpcheck?.type === 'file' ? callUfpList() : null,
-                       ]);
-               });
+                       callNetworkInterfaceDump(),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-4', '-j', 'neigh', 'show' ]), {}),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-4', '-j', 'route', 'show', 'table', 'all' ]), {}),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-4', '-j', 'rule', 'show' ]), {}),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-6', '-j', 'neigh', 'show' ]), {}),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-6', '-j', 'route', 'show', 'table', 'all' ]), {}),
+                       L.resolveDefault(fs.exec('/sbin/ip', [ '-6', '-j', 'rule', 'show' ]), {}),
+                       L.hasSystemFeature('ufpd') ? callUfpList() : null,
+               ]);
        },
 
        getNetworkByDevice(networks, dev, addr, mask, v6) {
index 3fda23977587e589a21db6be8bff1db53f1563d0..c9e3c836cb9e1c0470f150ae7b062c6389f31029 100644 (file)
@@ -34,8 +34,7 @@
                "read": {
                        "ubus": {
                                "luci-rpc": [ "getDHCPLeases" ],
-                               "fingerprint": [ "fingerprint" ],
-                               "file": [ "stat" ]
+                               "fingerprint": [ "fingerprint" ]
                        }
                }
        },
index 729cb177e34eb4147fda39ba382d5cdab661c4f4..f551669c4941a0aa769e35e1cbf5e6091587078b 100644 (file)
@@ -49,7 +49,7 @@
                                "/sbin/ip -[46] rule show": [ "exec" ]
                        },
                        "ubus": {
-                               "file": [ "exec", "stat" ],
+                               "file": [ "exec" ],
                                "fingerprint": [ "fingerprint" ]
                        }
                }
@@ -64,7 +64,7 @@
                                "/sbin/ip -[46] -j rule show": [ "exec" ]
                        },
                        "ubus": {
-                               "file": [ "exec", "stat" ],
+                               "file": [ "exec" ],
                                "fingerprint": [ "fingerprint" ]
                        }
                }